import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'author_logic.dart';
import 'widget/author_widget.dart';
import '../../routes/routes.dart';
import '../../widgets/widgets.dart';
import '../../shared/shared.dart';

class GenderPage extends GetView<AuthorLogic> {
  const GenderPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return WillPopScope(
        child: Stack(children: [
          const Background(
              imageURL: AssetsURL.backgroundPicture2, opacity: 0.56),
          Scaffold(
              backgroundColor: Colors.transparent, body: genderMain(context))
        ]),
        onWillPop: () async => false);
  }

  Widget genderMain(BuildContext context) {
    return SingleChildScrollView(
      child: Column(children: [
        const SizedBox(height: 120),
        const GenderHeader(),
        _buildPrompt('请选择您的性别', 15, 30),
        _buildGenderRow(),
        _buildPrompt('选择后不可更改', 30, 30),
        const SizedBox(height: 120),
        _confirmButton(context),
        CommonWidget.rowHeight(height: 150),
        UserAgreement(controller: controller)
      ]),
    );
  }

  BlindButton _confirmButton(BuildContext context) {
    return BlindButton(
      width: 113,
      height: 39,
      text: '确定',
      fontSize: 20,
      color: Colors.transparent,
      onTap: () {
        if (controller.state.gender.value == 1 ||
            controller.state.gender.value == 2) {
          if (controller.state.select.value) {
            Get.toNamed(Routes.author + Routes.gender + Routes.login,
                arguments: controller);
          } else {
            CommonWidget.toast('请同意用户协议');
          }
        } else {
          CommonWidget.toast('请先选择性别');
        }
      },
    );
  }

  Container _buildPrompt(String prompt, double top, double bottom) {
    return Container(
      margin: EdgeInsets.only(top: top, bottom: bottom),
      child: Text(prompt,
          style:
              const TextStyle(color: ColorConstants.themeColor, fontSize: 14)),
    );
  }

  Row _buildGenderRow() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: [
        SelectGender(
            iconNames: IconNames.boy,
            gender: '男生',
            controller: controller,
            select: 1),
        SelectGender(
            iconNames: IconNames.girl,
            gender: '女生',
            controller: controller,
            select: 2)
      ],
    );
  }
}
